//
//  LBRouterAction.m
//  LBRouter
//
//  Created by WuShiHai on 19/5/24.
//  Copyright (c) 2019 Lebbay. All rights reserved.
//

#import "LBRouterAction.h"

@interface LBRouterAction ()

@property (nonatomic, strong) NSMutableDictionary<NSString *, LBRouterActionCallbackBlock> *callBackCompleteHandlers;

@end

@implementation LBRouterAction

- (void)addRouterCallbackAction:(NSString *)callbackType
                 complteHandler:(LBRouterActionCallbackBlock)complteHandler{
    if (callbackType && complteHandler) {
        [self.callBackCompleteHandlers setObject:complteHandler forKey:callbackType];
    }
}

- (void)addDecideHandler:(LBRouterHandleDecideBlock)decideHandler{
    _decideHandler = decideHandler;
}

- (BOOL)routerComplete:(LBRouterType)type
             URLString:(NSString *)URLString
                 paths:(NSString *)paths
              userInfo:(NSDictionary *)userInfo{
    if (type == LBRouterTypeNativeCallback) {
        LBRouterActionCallbackBlock complteHandler = [self.callBackCompleteHandlers objectForKey:paths];
        if (complteHandler) {
            complteHandler();
            return YES;
        }
    }
    return NO;
}

- (NSMutableDictionary<NSString *,LBRouterActionCallbackBlock> *)callBackCompleteHandlers{
    if (_callBackCompleteHandlers) {
        return _callBackCompleteHandlers;
    }
    _callBackCompleteHandlers = [@{} mutableCopy];
    return _callBackCompleteHandlers;
}

@end
